package com.sport.mapper;

import com.sport.pojo.dto.UpdateUserDto;
import com.sport.pojo.dto.UserShow;
import com.sport.pojo.entity.Room;
import com.sport.pojo.entity.User;
import com.sport.pojo.vo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where user_account=#{userAccount}")
    User findUserByUserAccount(String userAccount);
    @Select("select a.*,b.teamleader_id from user as a join team as b on a.team_id=b.team_id where user_account=#{userAccount}")
    User  findUserByUserName(String userAccount);
    @Insert("insert into user (user_id,user_name,user_account,user_password,avatar)values (#{userId},#{userName},#{userAccount},#{userPassword},#{avatar})")
    int insertUser(User user);
    @Select("select * from user where user_id = #{userId}")
    User findUserMessageByUserId(String userId);
    @Update("update user set user_name = #{userName},sex = #{sex},height=#{height},weight=#{weight} where user_id = #{userId}")
    int userUpdateMessage(UpdateUserDto updateUserDto);
    @Select("select c.room_id,outcome,outcome_num,camp,end_time from uandr as b join user as a on a.user_id = b.user_id join room as c on b.room_id =c.room_id where b.user_id =#{user_id} and room_status=3 and battle_status=1 order by end_time desc;")
    List<HistoryVo> findHistoryByUserId(String userId);
    @Select("select user_name,avatar,user_football_dan from user order by user_football_dan desc")
    List<UserShow> showUserFootballDanRank();
     @Select("select a.user_id,user_name,sex,avatar,bg,height,weight,trial,slogan,user_football_dan,team,a.team_id,b.room_id,roomhost_id, c.max_num,camp,img_id ,d.teamleader_id ,student_verify from user as a join uandr as b on a.user_id = b.user_id\n" +
             "    join room as c on b.room_id = c.room_id\n" +"join team as d on a.team_id=d.team_id\n"+
             "    where a.user_id = #{currentId} and c.room_status !=3")
    UserAllInfoVo findUserAllByUserId(String currentId);
     @Update("update user set user_password = #{md5DigestAsHex} where user_id = #{currentId}")
    int updatePassword(String currentId, String md5DigestAsHex);
     @Update("update user set avatar = #{path} where user_id = #{currentId}")
    int  updateAvatar(String currentId, String path);
     @Update("update user set student_verify = 2,student_card=#{path} where user_id = #{currentId}")
    int studentVerification(String currentId, String path);

     @Select("select user_id,user_name,avatar,user_football_dan,student_card from user where student_verify=2")
    List<StudentVerifyVo> findStudentVerification();
    @Select("select user_id,user_name,avatar,user_football_dan,judge_card from user where trial=2")
    List<JudgeVerifyVo> findJudgeVerification();
    @Update("update user set student_verify = 1 where user_id = #{userId}")
    int agreeStudentVerification(String userId);
    @Update("update user set trial = 1 where user_id = #{userId}")
    int agreeJudgeVerification(String userId);
    @Select("select student_verify,trial from user where user_id=#{currentId}")
    VerifyVo findVerify(String currentId);
    @Update("update user set judge_card = #{path},trial=2 where user_id = #{userId}")
    int judgeVerification(String userId,String path);
    @Update("update user set student_verify = 0 where user_id = #{userId}")
    int disagreeStudentVerification(String userId);
    @Update("update user set trial = 0 where user_id = #{userId}")
    int disagreeJudgeVerification(String userId);
    @Select("select user_football_dan from user where user_id=#{currentId}")
    int getDao(String currentId);
}
